package com.vegetable.modules.controller.finance;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.vegetable.common.annotation.SysLog;
import com.vegetable.common.utils.R;
import com.vegetable.modules.controller.AbstractController;
import com.vegetable.modules.entity.finance.BankFlowImportConfig;
import com.vegetable.modules.entity.finance.po.BankFlowImportConfigQueryPO;
import com.vegetable.modules.service.finance.IBankFlowImportConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/bankFlowImportConfig")
@Api(value = "银行流水导入配置模块", tags = "银行流水导入配置模块")
public class BankFlowImportConfigController extends AbstractController {
    
    @Resource
    private IBankFlowImportConfigService bankFlowImportConfigService;
    
    @SysLog(value = "查询银行流水导入配置列表")
    @PostMapping("/list")
    @ApiOperation(value = "查询银行流水导入配置列表", notes = "查询银行流水导入配置列表")
    public R list(@RequestBody BankFlowImportConfigQueryPO po) {
        IPage<BankFlowImportConfig> result = bankFlowImportConfigService.queryPage(po);
        return R.data(result);
    }
    
    @SysLog(value = "查询所有启用的银行流水导入配置")
    @GetMapping("/allEnabled")
    @ApiOperation(value = "查询所有启用的银行流水导入配置", notes = "查询所有启用的银行流水导入配置")
    public R allEnabled() {
        List<BankFlowImportConfig> result = bankFlowImportConfigService.queryAllEnabled();
        return R.data(result);
    }
    
    @SysLog(value = "根据ID获取银行流水导入配置")
    @GetMapping("/info/{id}")
    @ApiOperation(value = "根据ID获取银行流水导入配置", notes = "根据ID获取银行流水导入配置")
    public R info(@PathVariable("id") Long id) {
        BankFlowImportConfig config = bankFlowImportConfigService.getById(id);
        return R.data(config);
    }
    
    @SysLog(value = "根据银行类型获取银行流水导入配置")
    @GetMapping("/getByBankType")
    @ApiOperation(value = "根据银行类型获取银行流水导入配置", notes = "根据银行类型获取银行流水导入配置")
    public R getByBankType(@RequestParam("bankType") String bankType) {
        BankFlowImportConfig config = bankFlowImportConfigService.getByBankType(bankType);
        return R.data(config);
    }
    
    @SysLog(value = "保存银行流水导入配置")
    @PostMapping("/save")
    @ApiOperation(value = "保存银行流水导入配置", notes = "保存银行流水导入配置")
    public R save(@RequestBody BankFlowImportConfig config) {
        config.setCreateUserId(getUserId());
        boolean result = bankFlowImportConfigService.saveConfig(config);
        return result ? R.success("保存成功") : R.fail("保存失败");
    }
    
    @SysLog(value = "更新银行流水导入配置")
    @PostMapping("/update")
    @ApiOperation(value = "更新银行流水导入配置", notes = "更新银行流水导入配置")
    public R update(@RequestBody BankFlowImportConfig config) {
        config.setUpdateUserId(getUserId());
        boolean result = bankFlowImportConfigService.updateConfig(config);
        return result ? R.success("更新成功") : R.fail("更新失败");
    }
    
    @SysLog(value = "删除银行流水导入配置")
    @PostMapping("/delete/{id}")
    @ApiOperation(value = "删除银行流水导入配置", notes = "删除银行流水导入配置")
    public R delete(@PathVariable("id") Long id) {
        boolean result = bankFlowImportConfigService.deleteConfig(id);
        return result ? R.success("删除成功") : R.fail("删除失败");
    }
}